﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using XrmLibrary;
using XrmLibrary.Context;

namespace OrganizerLibrary.Processors
{
    public abstract class ProcessorBase
    {
        protected FileSystemInfo FileInfo;

        protected ProcessorBase(FileSystemInfo fileInfo)
        {
            FileInfo = fileInfo;
        }

        public virtual void Process()
        {
            try
            {
                File.Move(GetSourceFilePath(), GetTargetFilePath());
                Tracer.Log(LogContext.InstantiateSuccess(this, "The file was successfully moved."));
            }
            catch (Exception ex)
            {
                Tracer.Log(LogContext.InstantiateError(this, ex, "An error occurred while trying to move the file."));
            }
        }

        protected abstract String GetTargetDirectory();

        protected String GetFileName()
        {
            return FileInfo.Name;
        }

        protected String GetSourceFilePath()
        {
            return FileInfo.FullName;
        }

        protected String GetTargetFilePath()
        {
            return Path.Combine(GetTargetDirectory(), GetFileName());
        }

        public override string ToString()
        {
            return String.Format("Processor: [{0}]", GetFileName());
        }
    }
}
